package com.crawler.entity;

import java.util.Date;

import org.apache.http.client.methods.HttpRequestBase;

import com.core.entity.BaseModel;
import com.core.plugin.bind.Table;
import com.crawler.pojo.PageType;
@SuppressWarnings("serial")
@Table(name = "crawlerLog")
public class CrawlerLog extends BaseModel<CrawlerLog> {
	
	public static final CrawlerLog me = new CrawlerLog();

	/**
	 * 请求的日志
	 */
	public void save(String operType,String loginName, String password,HttpRequestBase httpRequest,String operResult,String resultMsg,String html) {
		CrawlerLog crawlerLog = new CrawlerLog();
		if(httpRequest != null){
			String ip = null;
			String port = null;
			if(httpRequest.getConfig() != null){
				ip = httpRequest.getConfig().getProxy().getAddress().getHostAddress();
				port = httpRequest.getConfig().getProxy().getPort()+"";
			}
			crawlerLog.set("ip", ip);
			crawlerLog.set("port", port);
			crawlerLog.set("httpMethod", httpRequest.getMethod());
			crawlerLog.set("url", httpRequest.getURI().toString());
		}
		crawlerLog.set("operType", operType);
		crawlerLog.set("loginName", loginName);
		crawlerLog.set("password", password);
		crawlerLog.set("operResult", operResult);
		crawlerLog.set("resultMsg", resultMsg);
		crawlerLog.set("createTime", new Date());
		crawlerLog.set("html", html);
		save(crawlerLog);
	}
	
	/**
	 * 响应的日志
	 */
	public void save(String operType,String loginName, String password,String url,String operResult,String resultMsg,String html) {
		CrawlerLog crawlerLog = new CrawlerLog();
		crawlerLog.set("url", url);
		crawlerLog.set("operType", operType);
		crawlerLog.set("loginName", loginName);
		crawlerLog.set("password", password);
		crawlerLog.set("operResult", operResult);
		crawlerLog.set("resultMsg", resultMsg);
		crawlerLog.set("createTime", new Date());
		crawlerLog.set("html", html);
		save(crawlerLog);
	}

	/**
	 * 解析的日志
	 */
	public void save(String operType, PageType pageType, String operResult,String resultMsg, String html) {
		CrawlerLog crawlerLog = new CrawlerLog();
		crawlerLog.set("url", pageType.getUrl());
		crawlerLog.set("loginName", pageType.getLoginName());
		crawlerLog.set("operType", operType);
		crawlerLog.set("operResult", operResult);
		crawlerLog.set("resultMsg", resultMsg);
		crawlerLog.set("createTime", new Date());
		crawlerLog.set("html", html);
		save(crawlerLog);
	}


}
